import { Component, OnInit } from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
@Component({
  selector: 'app-product',
  templateUrl: './product.component.html',
  styleUrls: ['./product.component.css']
})
export class ProductComponent implements OnInit {
  private productID:number;
  private productName: string;
  constructor(private routeInfo: ActivatedRoute) { }

  ngOnInit() {
  
    // this.productID = this.routeInfo.snapshot.queryParams["id"];
    this.routeInfo.params.subscribe((params: Params) => this.productID = params['id']);//订阅方式(如果改路由组件跳转到该路由组件的时候用该种方法)
    // this.productID = this.routeInfo.snapshot.params["id"]; //快照方式()
    this.routeInfo.data.subscribe((data: {product: Product}) => {
      this.productID = data.product.id;
      this.productName = data.product.name;
    });  
  }

}

export class Product {
  constructor(public id:number, public name:string){}
}
